import { STLabel } from "../types";



export function CompLabel<T extends { new (...args: any[]): {} }>(
  constructor: T
) {
  constructor.prototype.showLabels = function () {
    if(!this.labelBox) return;
    this.labelBox.style.display = "block";
  };

  constructor.prototype.hideLabels = function () {
    if(!this.labelBox) return;
    this.labelBox.style.display = "none";
  };

  constructor.prototype.createLabels = function (labels: STLabel[]) {    
    if (this.labelBox !== null) return;
    this.labelBox = document.createElement("div");
    this.labelBox.style.position = "absolute";
    this.labelBox.style.top = "0";
    this.labelBox.style.left = "0";
    this.labelBox.style.zIndex = "9";
    labels.forEach((label) => {
      const div = document.createElement("div");
      div.innerText = label.key + ": " + label.value;
      this.labelBox.appendChild(div);
      this.labels.push(div);
      if(label.style) {
        div.style.color = label.style.color || "black"
        div.style.fontSize = label.style.fontSize || "16px"
      }
    });
    switch (labels[0].position) {
      case "left-top":
        this.labelBox.style.top = "10px";
        this.labelBox.style.left = "10px";
        break
      case "left-bottom":
        this.labelBox.style.top = "10px";
        this.labelBox.style.left = "10px";
        break
      case "right-top":
        this.labelBox.style.top = "10px";
        this.labelBox.style.right = "10px";
        break
      case "right-bottom":
        this.labelBox.style.bottom = "10px";
        this.labelBox.style.right = "10px";
        break
    }
  };

  return class extends constructor {
    labels: STLabel[] = [];
    labelBox: HTMLElement | null = null;
  };
}
